<?php get_instance()->view('common/header');?>
<link rel="stylesheet" href="<?php echo $this->staticUrl?>css/jquery-weui.css">
<style>
    .swiper-pagination-bullet-active{background:#f1cd31;}
    .weui-picker-container{height:100%;background:rgba(0,0,0,0.5);}
    .weui-cell_primary p{text-align:center;}
    .weui-cells_radio .weui-cell__ft{display:none;}
	.indextitle{padding:1em 0; background:#fff;margin:0 auto;}
	.waper{background:#fff;}
	.saixuan{background:#fff;}
	.discount{display:block;float:left;}
	.discount img{width:100%;margin-top:1px;}
	.conentbox{display:block;}
	.conentbox .pr{float:left;}
	.conentbox .model{padding-left:5.75em;}
	.conentbox:after{clear:both;content:'';display:block;}
	.juli{top:1.25em;display:block;text-align:right;}
	.juli .shu{height:0.25em;}
	.banner{margin-bottom:0.5em;}
    .threebox{height:260px;background:#fff;padding:0;}
    .threebox .left{height:100%;}
    .threebox .right .right_top{height:127.5px;margin-bottom:5px;display:block;}
    .threebox .right .right_bottom{height:127.5px;display:block;}
    .threebox img{height:100%;}
    .threebox .right img{margin-bottom:0;}
</style>
<body class="bag1">
    <div class="weui-tab">
        <div class="pb30">
            <div class="indextop pr">
                <img class="mbg" src="<?php echo $tData['home_top']['imgs']?>" alt="">
                <a href="<?php echo getUrl('home/address')?>">
                    <div class="dingwei f08">
                        <img class="heightimg mr5 di mbmin" src="<?php echo $this->staticUrl?>img/png/pic132.png" alt="">
                        <c id="address_"><?php echo !empty($this->address)&&$reload == 1 ? $this->address : '定位中...'?></c>
                    </div>
                </a>
                <a href="<?php echo getUrl('home/search')?>">
                    <div class="pos" style="bottom: 10px;left: 50%;margin-left: -45%;width: 90%;"><img class="wp100" src="<?php echo $this->staticUrl?>img/png/pic142.png" alt=""></div>
                </a>
            </div>
            <div class=" swiper-container indexmenu bag1">
                <div class="swiper-wrapper">
                    <?php foreach ($category as $k => $v):?>
                        <div class="swiper-slide">
                            <a <?php if ($v['id'] == 1): ?> href="<?php echo getUrl('dailyMenus')?>"
                            <?php elseif($v['id'] == 2):?> href="<?php echo getUrl('find/find')?>"
                            <?php elseif($v['id'] == 3):?> href="javascript:;"
                            <?php else:?> href="<?php echo getUrl('home/shop?category_id='.$v['id'])?>"
                            <?php endif;?>
                                    class="menu <?php if($v['id'] == 3):?>button-share <?php endif;?>">
                                <img src="<?php echo $v['pic']?>" class="m0a" alt="">
                                <?php echo $v['cat_name']?>
                            </a>
                        </div>
                    <?php endforeach;?>
                </div>
            </div>
            <div class="swiper-container banner">
                <div class="swiper-wrapper">
                    <?php foreach ($tData['lunbo'] as $k => $v):?>
                        <div class="swiper-slide">
                            <a <?php $m = $v['merchant_id']; $u = $v['url'];
                                if($v['type'] == 1 && $u):?> href="<?php echo $u?>"
                                <?php elseif($v['type'] == 2 && $m):?> href="<?php echo getUrl('product/merchant?merchant_id='.$m)?>"
                                <?php elseif($v['type'] == 3 && $v['param']):?> href="<?php echo getUrl('product/info?merchant_id='.$m.'&product_id='.$v['param'])?>"
                                <?php elseif($v['type'] == 4 && $v['param']):?> href="<?php echo getUrl('home/shop?category_id='.$v['param'])?>"
                                <?php else:?> href="javascript:;" <?php endif;?> >
                                <img src="<?php echo $v['imgs']?>" alt="">
                            </a>
                        </div>
                    <?php endforeach;?>
                </div>
                <div class="swiper-pagination"></div>
            </div>
            <div class="">
                <div class="jdjz indextitle"><img src="<?php echo $this->staticUrl?>img/png/pic129.png" alt=""></div>
                <div class="threebox heng bag1">
                    <a <?php
                        $lm = $tData['home_middle_left']['merchant_id'];
                        $lp = $tData['home_middle_left']['param'];
                        $lu = $tData['home_middle_left']['url'];
                        $lt = $tData['home_middle_left']['type'];
                        if($lt == 1 && $lu):?> href="<?php echo $lu?>"
                        <?php elseif($lt == 2 && $lm):?> href="<?php echo getUrl('product/merchant?merchant_id='.$lm)?>"
                        <?php elseif($lt == 3 && $lp):?> href="<?php echo getUrl('product/info?merchant_id='.$lm.'&product_id='.$lp)?>"
                        <?php elseif($lt == 4 && $lp):?> href="<?php echo getUrl('home/shop?category_id='.$lp)?>"
                         <?php else:?> href="javascript:;" <?php endif;?> class="left">
                        <img src="<?php echo $tData['home_middle_left']['imgs']?>" alt="">
                    </a>
                    <div class="right">
                        <a <?php
                            $rtm = $tData['home_middle_right_top']['merchant_id'];
                            $rtp = $tData['home_middle_right_top']['param'];
                            $rtu = $tData['home_middle_right_top']['url'];
                            $rtt = $tData['home_middle_right_top']['type'];
                            if($rtt == 1 && $rtu):?> href="<?php echo $rtu?>"
                            <?php elseif($rtt == 2 && $rtm):?> href="<?php echo getUrl('product/merchant?merchant_id='.$rtm)?>"
                            <?php elseif($rtt == 3 && $rtp):?> href="<?php echo getUrl('product/info?merchant_id='.$rtm.'&product_id='.$rtp)?>"
                            <?php elseif($rtt == 4 && $rtp):?> href="<?php echo getUrl('home/shop?category_id='.$rtp)?>"
                            <?php else:?> href="javascript:;" <?php endif;?> class="right_top">
                            <img src="<?php echo $tData['home_middle_right_top']['imgs']?>" alt="">
                        </a>
                        <a <?php
                            $rdm = $tData['home_middle_right_down']['merchant_id'];
                            $rdp = $tData['home_middle_right_down']['param'];
                            $rdu = $tData['home_middle_right_down']['url'];
                            $rdt = $tData['home_middle_right_down']['type'];
                            if($rdt == 1 && $rdu):?> href="<?php echo $rdu?>"
                            <?php elseif($rdt == 2 && $rdm):?> href="<?php echo getUrl('product/merchant?merchant_id='.$rdm)?>"
                            <?php elseif($rdt == 3 && $rdp):?> href="<?php echo getUrl('product/info?merchant_id='.$rdm.'&product_id='.$rdp)?>"
                            <?php elseif($rdt == 4 && $rdp):?> href="<?php echo getUrl('home/shop?category_id='.$rdp)?>"
                            <?php else:?> href="javascript:;" <?php endif;?> class="right_bottom">
                            <img src="<?php echo $tData['home_middle_right_down']['imgs']?>" alt="">
                        </a>
                    </div>
                </div>
            </div>
            <div class="jdjz indextitle"><img src="<?php echo $this->staticUrl?>img/png/pic131.png" alt=""></div>
            <div class="saixuan">
                <a href="javascript:;" class="sort actived" data-id="2">综合排序</a>
                <a href="javascript:;" class="sort " data-id="1">距离最近</a>
                <a href="javascript:;" class="sort" data-id="3">评分最高</a>
                <a href="javascript:;" >
                    <b class="b0" id="category" value="">分类筛选</b>
                    <img class="jiantou" src="<?php echo $this->staticUrl?>img/png/pic9.png">
                </a>
                <div class="after"></div>
            </div>
            <?php if (!empty($list)):?>
                <div class="waper">
                    <div class="list">
                        <?php foreach ($list as $k => $v):?>
                            <div class="conentbox hengleft merchant" data-id="<?php echo $v['id']?>">
                                <div class="imgbox mr10 pr">
                                    <img src="<?php echo $v['headurl']['xs']?>" alt="">
                                    <?php if ($v['business'] == 1):?>
                                        <div class="zezao business_zz" ></div>
                                        <img class="pos xi" src="<?php echo $this->staticUrl?>img/png/pic143.png" alt="">
                                    <?php endif;?>
                                </div>
                                <div class="model">
                                    <div class="hengleft vCenter"><p class="mr5 lh10 f09 fb"><?php echo $v['shop_name']?></p></div>
                                    <div class="hengleft f08 mt5 mb5 vCenter">
                                        <div class="xing hengleft vCenter">
                                            <?php for ($i = 0; $i < $v['score']; $i++):?>
                                                <img src="<?php echo $this->staticUrl?>img/png/pic11.png" alt="">
                                            <?php endfor; $score = 5-$v['score']; for ($j = 0; $j < $score; $j++):?>
                                                <img src="<?php echo $this->staticUrl?>img/png/pic12.png" alt="">
                                            <?php endfor;?>
<!--                                            <span class="hongzi f09">--><?php //echo $v['score']?><!--</span>-->
                                        </div>
                                        <span class="shu"></span>
                                        <span class="f08">月售<?php echo $v['month_total']?>单</span>
                                    </div>
                                    <?php  if(!empty($v['business_desc'])): ?>
                                        <span class="f06" style="background-color: #0c91e5;color: white;padding: 0.1em 0.5em;"><?php echo $v['business_desc'] ?></span>
                                    <?php  endif; ?>
                                    <?php if (!empty($v['note'])): foreach ($v['note'] as $kk => $vv):?>
                                        <div class="f085">
                                            <span class="discount"><img src="<?php echo $vv['icon']?>" alt=""></span>
                                            <p class="f08 cor8 textEll"><?php echo $vv['text']?></p>
                                        </div>
                                    <?php endforeach; endif;?>
                                </div>
                                <p class="cor9 juli vCenter">
									<?php  if ($v['distance'] >= 1000)
                                    { $d = ceil($v['distance']/1000); echo $d.'km';}
                                    else{ echo $v['distance'].'m';}?>
								<span class="dk shu"></span>预计<?php echo $v['expect_arrive_time']?>分钟
                                </p>
                            </div>
                        <?php endforeach;?>
                    </div>
                    <div class="weui-loadmore" style="display: none">
                        <div class="load">
                            <i class="weui-loading"></i>
                            <span class="weui-loadmore__tips">正在加载</span>
                        </div>
                        <span class="noC f085" style="display: none">没有更多内容了~</span>
                    </div>
                </div>
            <?php else:?>
                <div class="statebox chuizhi jdjz" style="flex: 1;height: 100%;">
                    <img class="stateimgda mb5" src="<?php echo $this->staticUrl?>img/default/2.png" alt="">
                    <span class="f09 cor9 tc mb20">暂无数据</span>
                </div>
            <?php endif;?>
        </div>

    </div>
    <div class="share jdjz" style="z-index: 2;">
    <span class="simg">
        <img src="<?php echo $this->staticUrl;?>img/png/share.png" alt="">
    </span>
    </div>

<div id="allmap"></div>
    <?php get_instance()->view('common/footer');?>
    <?php get_instance()->view('common/wxJssdk');?>
</body>
<script src="<?php echo $this->staticUrl?>js/jquery-weui.js"></script>
<script src="<?php echo $this->staticUrl?>js/base.js"></script>
<script type="text/javascript">
    var page = 1,
        sort = 2,
        category_id,
        html,
        l = "<?php echo $this->staticUrl?>img/png/pic11.png", // 星级 - 亮
        a = "<?php echo $this->staticUrl?>img/png/pic12.png", // 星级 - 暗
        d = "<?php echo $this->staticUrl?>img/default/2.png"; // 缺省图
    var loading = false;  //状态标记
    $(function () {

        /**
         * 排序
         */
        $(".sort").click(function () {
            sort = $(this).attr('data-id');
            page = 1;
            //blockUI.show('加载中...');
            $(".sort").removeClass('actived');
            $(this).addClass('actived');
            var weiz = $(".saixuan a.actived").index();
            var wid = $(".saixuan a").width();
            $(".saixuan .after").animate({left:weiz*wid});
            getList(0);
            $(document.body).infinite();
        });

        /**
         * 点击分类
         * [{title: "iPhone 3GS",value: "001",}]
         */
        $("#category").select({
            title: "选择分类",
            items: <?php echo $shopCategory?>,
            onClose:function () {
                category_id = $("#category").attr('data-values');
                if (category_id == undefined){
                    return;
                }
                var cat = $("#category").attr('value');
                $("#category").html(cat);
                page = 1;
                blockUI.show('加载中...');
                getList(0);
                $(document.body).infinite();
            }
        });

        /**
         * 上拉加载
         */
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            $(".weui-loadmore").show();
            $(".load").show();
            $(".noC").hide();
            // $(document.body).destroyInfinite() // 销毁插件
            // $(document.body).infinite() // 重新初始化
            page += 1;
            getList(1)
        });


        /**
         * 点击跳转
         */
        $(".list").delegate('.merchant', 'click', function () {
            var merchantId = $(this).attr('data-id');
            window.location.href = "<?php echo getUrl('product/merchant?merchant_id=')?>"+merchantId
        });
    });

    function getList(t) {
        var xi = "<?php echo $this->staticUrl?>img/png/pic143.png";
        $.ajax('<?php echo getUrl('home/getShopList');?>', {
            type:'post',
            data:{page:page,category_id:category_id,sort:sort},
            dataType:'json',
            error:function(){
                blockUI.hide();
                show_message({status:0, message:'请求超时'});
            },
            timeout:60000,
            success:function(e,textStatus,jqXHR){
                blockUI.hide();
                loading = false;
                if (e.status != 1){
                    show_message(e);
                    return;
                }

                if (t == 1){
                    if (!e.data.length){
                        $(document.body).destroyInfinite();
                        $(".load").hide();
                        $(".noC").show();
                        return;
                    }
                }else{
                    if (!e.data.length){
                        $(".weui-loadmore").hide();
                        $(".list").html('<div class="statebox chuizhi jdjz" style="flex: 1;height: 100%;">' +
                            '<img class="stateimgda mb5" src="'+d+'" alt="">' +
                            '<span class="f09 cor9 tc mb20">暂无数据</span></div>');
                        return;
                    }else{
                        $(".list").html('');
                    }
                }

                $(".weui-loadmore").hide();
                html = '';
                $.each(e.data, function (key, obj) {
                    var score = '',
                        s = 5 - obj.score,
                        note = '',
                        distance = obj.distance+'m',
                        xiImg = '';
                    for (var i = 0; i < obj.score; i++){
                        score += '<img src="'+l+'" alt="">';
                    }
                    if (s > 0){
                        for (var j = 0; j < s; j++){
                            score += '<img src="'+a+'" alt="">';
                        }
                    }
//                        if ($.inArray("note", obj) > -1){
                    if (obj.note){
                        $.each(obj.note, function (k, v) {
                            note +=
                                '<div class="f085">' +
                                '   <span class="discount"><img src="'+v.icon+'" alt=""></span>' +
                                '   <p class="f08 cor8 textEll">'+v.text+'</p>' +
                                '</div>';
                        })
                    }

                    if (obj.distance >= 1000){
                        distance = obj.distance/1000;
                        distance = distance + 'km'
                    }
                    if (obj.business == 1){
                        xiImg = '<div class="zezao business_zz" ></div><img class="pos xi" src="'+xi+'" alt="">'
                    }
                    var business_desc ="";
                    if(obj.business_desc!=""){
                        business_desc='<span class="f06" style="background-color: #0c91e5;color: white;padding: 0.1em 0.5em;">'+obj.business_desc+'</span>'
                    }
                    html =
                        '<div class="conentbox hengleft merchant" data-id="'+obj.id+'">' +
                        '   <div class="imgbox mr10 pr"><img src="'+obj.headurl.xs+'" alt="">'+xiImg+'</div>' +
                        '   <div class="model">' +
                        '       <div class="hengleft vCenter"><p class="mr5 lh10 f09 fb">'+obj.shop_name+'</p></div>' +
                        '       <div class="hengleft f08 mt5 mb5 vCenter">' +
                        '           <div class="xing hengleft vCenter">'+score+
//                        '               <span class="hongzi f09">'+obj.score+'</span>' +
                        '           </div>' +
                        '           <span class="shu"></span>' +
                        '           <span class="f08">月售'+obj.month_total+'单</span>' +
                        '       </div>'+business_desc+note+
                        '   </div>' ;

                    html += '   <p class="cor9 juli vCenter">'+distance+
                        '       <span class="dk shu"></span>预计'+obj.expect_arrive_time+'分钟</p>' +
                        '</div>';
                    $(".list").append(html);
                });
            }
        });
    }
</script>

<script type="text/javascript" src="<?php echo $this->staticUrl?>js/qqapi.js?v=1.0"></script>
<script type="text/javascript">
    $(function () {
        var address = "<?php echo $this->address;?>";
        var reload = "<?php echo $reload;?>";
        if(reload == 2){
            WeChat();
        }

        $(".button-share").on('click',function () {
            $(".share").css("visibility","visible");
            WeChatShare();
        });

        $(".share").click(function(){
            $(this).css("visibility","hidden");
        });
    });

function setAddress(lat,lng){
//	$('#address_').text(res.detail.name);
//	var lat = res.detail.latLng.lat;
//	var lng = res.detail.latLng.lng;
    var load = false;
    $.ajax('<?php echo getUrl('home/setLonLat');?>', {
        type:'post',
        data:{latitude:lat,longitude:lng,type:'wgs84'},
        dataType:'json',
        error:function(){
            blockUI.hide();
            show_message({status:0, message:'请求超时'});
        },
        timeout:60000,
        success:function(e,textStatus,jqXHR){
            $('#address_').text(e.data[2]);
//            window.location.reload(true);
            window.location.href = "<?php echo getUrl('home/index?reload=1');?>";
            page = 1;
            getList(2);
        }
    });
}
$(window).scroll(function(){
     if($(window).scrollTop() >= 800){
        $('.saixuan').css({'position':'fixed','top':'0',"width":"100%","left":'0','z-index':'2'});
     }else {
        $('.saixuan').css('position','');
     };
})
</script>
</html>